﻿Public Partial Class AdvertiserReport
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        LoadReport()

    End Sub

    Private Sub LoadReport()
        If Page.User.Identity.IsAuthenticated Then
            Dim manager As New BLL.AdvertiserManager
            Dim advertiser As Domain.dnc_Advertiser
            advertiser = manager.GetAdvertiser(BLL.UserManager.GetInstance().GetUsername())
            If Not advertiser Is Nothing Then
                If Not advertiser.ID = 0 Then

                    ' Get first advertisement to display
                    Dim adManager As New BLL.AdvertisementManager
                    Dim advertisement As List(Of Domain.dnc_Advertisement)
                    advertisement = adManager.GetAdvertisementByAdvertiserID(advertiser.ID)

                    For Each ad As Domain.dnc_Advertisement In advertisement
                        ad.Impressions = adManager.GetImpressions(ad.ID).number
                        ad.ClickThroughs = adManager.GetClickThroughs(ad.ID).number
                    Next

                    gvAdvertisements.DataSource = advertisement
                    gvAdvertisements.DataBind()
                Else
                    AdvertiserNotFound()
                End If
            Else
                AdvertiserNotFound()
            End If
        Else
            pnlReporting.Visible = False
            lblInformation.Text = " You must login to view your advertiser report."
        End If

    End Sub

    Private Sub AdvertiserNotFound()
        pnlReporting.Visible = False
        lblInformation.Text = "You do not have an advertising account with us. Please create one by emailing us before viewing this page"
    End Sub

End Class